<template>
  <div class="app-container">


    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['containResult:containResult:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['containResult:containResult:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['containResult:containResult:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['containResult:containResult:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="containResultList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="期数" align="center" prop="containId" />
        <el-table-column label="开奖号" align="center" prop="containId" >
          <template></template>
          </el-table-column>
      <el-table-column label="号" align="center" prop="firstNum" />
      <el-table-column label="${comment}" align="center" prop="secondNum" />
      <el-table-column label="${comment}" align="center" prop="thirdNum" />
      <el-table-column label="${comment}" align="center" prop="fouthNum" />
      <el-table-column label="${comment}" align="center" prop="fifithNum" />
      <el-table-column label="${comment}" align="center" prop="sixNum" />
      <el-table-column label="${comment}" align="center" prop="sevenNum" />
      <el-table-column label="采集类型" align="center" prop="containType" />
      <el-table-column label="奖金金额" align="center" prop="awardPrice" />
      <el-table-column label="花费金额" align="center" prop="costMoney" />
      <el-table-column label="一等奖" align="center" prop="firstAwardPrice" />
      <el-table-column label="二等奖" align="center" prop="secondAwardPrice" />
      <el-table-column label="三等奖" align="center" prop="thirdAwardPrice" />
      <el-table-column label="四等奖" align="center" prop="fourthAwardPrice" />
      <el-table-column label="五等奖" align="center" prop="fifthAwardPrice" />
      <el-table-column label="六等奖" align="center" prop="sixthAwardPrice" />
      <el-table-column label="七等奖" align="center" prop="seventhAwardPrice" />
      <el-table-column label="八等奖" align="center" prop="eighthAwardPrice" />
      <el-table-column label="九等奖" align="center" prop="nineAwardPrice" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['containResult:containResult:edit']"
          >修改</el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['containResult:containResult:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改当期结果对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="${comment}" prop="containId">
          <el-input v-model="form.containId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="号" prop="firstNum">
          <el-input v-model="form.firstNum" placeholder="请输入号" />
        </el-form-item>
        <el-form-item label="${comment}" prop="secondNum">
          <el-input v-model="form.secondNum" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="thirdNum">
          <el-input v-model="form.thirdNum" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="fouthNum">
          <el-input v-model="form.fouthNum" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="fifithNum">
          <el-input v-model="form.fifithNum" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="sixNum">
          <el-input v-model="form.sixNum" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="sevenNum">
          <el-input v-model="form.sevenNum" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="奖金金额" prop="awardPrice">
          <el-input v-model="form.awardPrice" placeholder="请输入奖金金额" />
        </el-form-item>
        <el-form-item label="花费金额" prop="costMoney">
          <el-input v-model="form.costMoney" placeholder="请输入花费金额" />
        </el-form-item>
        <el-form-item label="一等奖" prop="firstAwardPrice">
          <el-input v-model="form.firstAwardPrice" placeholder="请输入一等奖" />
        </el-form-item>
        <el-form-item label="二等奖" prop="secondAwardPrice">
          <el-input v-model="form.secondAwardPrice" placeholder="请输入二等奖" />
        </el-form-item>
        <el-form-item label="三等奖" prop="thirdAwardPrice">
          <el-input v-model="form.thirdAwardPrice" placeholder="请输入三等奖" />
        </el-form-item>
        <el-form-item label="四等奖" prop="fourthAwardPrice">
          <el-input v-model="form.fourthAwardPrice" placeholder="请输入四等奖" />
        </el-form-item>
        <el-form-item label="五等奖" prop="fifthAwardPrice">
          <el-input v-model="form.fifthAwardPrice" placeholder="请输入五等奖" />
        </el-form-item>
        <el-form-item label="六等奖" prop="sixthAwardPrice">
          <el-input v-model="form.sixthAwardPrice" placeholder="请输入六等奖" />
        </el-form-item>
        <el-form-item label="七等奖" prop="seventhAwardPrice">
          <el-input v-model="form.seventhAwardPrice" placeholder="请输入七等奖" />
        </el-form-item>
        <el-form-item label="八等奖" prop="eighthAwardPrice">
          <el-input v-model="form.eighthAwardPrice" placeholder="请输入八等奖" />
        </el-form-item>
        <el-form-item label="九等奖" prop="nineAwardPrice">
          <el-input v-model="form.nineAwardPrice" placeholder="请输入九等奖" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listContainResult, getContainResult, delContainResult, addContainResult, updateContainResult } from "@/api/containResult/containResult";

export default {
  name: "ContainResult",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 当期结果表格数据
      containResultList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        containId: null,
        firstNum: null,
        secondNum: null,
        thirdNum: null,
        fouthNum: null,
        fifithNum: null,
        sixNum: null,
        sevenNum: null,
        containType: null,
        awardPrice: null,
        costMoney: null,
        firstAwardPrice: null,
        secondAwardPrice: null,
        thirdAwardPrice: null,
        fourthAwardPrice: null,
        fifthAwardPrice: null,
        sixthAwardPrice: null,
        seventhAwardPrice: null,
        eighthAwardPrice: null,
        nineAwardPrice: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询当期结果列表 */
    getList() {
      this.loading = true;
      listContainResult(this.queryParams).then(response => {
        this.containResultList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        containId: null,
        firstNum: null,
        secondNum: null,
        thirdNum: null,
        fouthNum: null,
        fifithNum: null,
        sixNum: null,
        sevenNum: null,
        containType: null,
        awardPrice: null,
        costMoney: null,
        firstAwardPrice: null,
        secondAwardPrice: null,
        thirdAwardPrice: null,
        fourthAwardPrice: null,
        fifthAwardPrice: null,
        sixthAwardPrice: null,
        seventhAwardPrice: null,
        eighthAwardPrice: null,
        nineAwardPrice: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加当期结果";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getContainResult(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改当期结果";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContainResult(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addContainResult(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除当期结果编号为"' + ids + '"的数据项？').then(function() {
        return delContainResult(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('containResult/containResult/export', {
        ...this.queryParams
      }, `containResult_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
